package com.kadron.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.validator.NotNull;

import com.kadron.base.KBase;

@Entity
@Table(name = "k_discount_source")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER)
public abstract class AbstractDiscountSource extends KBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2708687959377545117L;

	private Discount discount;
	private int type;
	
	public AbstractDiscountSource() {
		super();
	}

	public AbstractDiscountSource(Discount discount, int type) {
		super();
		this.discount = discount;
		this.type = type;
	}

	@NotNull
	@ManyToOne(targetEntity = Discount.class)
	@JoinColumn(name = "discount_id", nullable = false, updatable = false)
	public Discount getDiscount() {
		return discount;
	}

	public void setDiscount(Discount discount) {
		this.discount = discount;
	}

	@Column(name = "type", nullable = false, updatable = false, insertable = false)
	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractDiscountSource other = (AbstractDiscountSource) obj;
		if (id != other.id)
			return false;
		return true;
	}

}
